#include "systemc.h"
#include "input.cpp"
#include "output.cpp"

SC_MODULE(router){

	unsigned short X,Y;
	unsigned short targetX,targetY;

	sc_in_clk clock;
	sc_out< sc_lv<8> > data;

	sc_fifo<unsigned short> fifo;

	/* 1 - left
	   2 - down
	   3 - right
	   4 - up
	   5 - local
	*/

	input in1,in2,in3,in4,in5;  
	output out1,out2,out3,out4,out5;
		 	 
	void route(){ //first four bits of the header - coordinates
		if (!fifo){ // start communication
			targetX = data.read().range(0,1).to_uint();
			targetY = data.read().range(2,3).to_uint();
			if (targetX < X){ 
				// sent packet left
			}
			else if (targetX > X){ 
				// sent packet right
			}
			else if (targetY < Y){ 
				// sent packet up
			}
			else if (targetY > Y){ 
				// sent packet down
			}
			else{
				//destination
			}
		}
		else{ // stop communication
			cout << "\n Communication stopped";
		}
	}

	SC_HAS_PROCESS(router);
	router(sc_module_name name,unsigned short Xcor=0,unsigned short Ycor=0) :
	sc_module(name),in1("in1"),in2("in2"),in3("in3"),in4("in4"),in5("in5"),
	out1("out1"),out2("out2"),out3("out3"),out4("out4"),out5("out5"){

		X = Xcor;
	    Y = Ycor;

		SC_THREAD(route);
		sensitive << clock.pos();
	}


};